/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.admin.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import org.apache.ibatis.annotations.Param;
import org.springblade.modules.admin.dto.rescue.PlanAddUserSearchDTO;
import org.springblade.modules.admin.dto.rescue.RescueListDTO;
import org.springblade.modules.admin.dto.sugar.rescue.SugarRescueSearchDTO;
import org.springblade.modules.admin.entity.MaintainMalfunctionRescue;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.admin.entity.MaintainPlanContent;
import org.springblade.modules.admin.entity.MaintainPlanContentExt;
import org.springblade.modules.admin.vo.*;
import org.springblade.modules.admin.vo.plan.PlanRescueDetailVO;
import org.springblade.modules.admin.vo.plan.TodayTaskListVO;
import org.springblade.modules.admin.vo.rescue.*;
import org.springblade.modules.admin.vo.rescue.map.MapRescuePlanDetailVO;
import org.springblade.modules.admin.vo.rescue.map.MapUserInfoCardDetailPlanListVO;
import org.springblade.modules.admin.vo.sugar.rescue.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 救援工单明细 Mapper 接口
 *
 * @author ysq
 * @since 2023-02-25
 */
public interface MaintainMalfunctionRescueMapper extends BaseMapper<MaintainMalfunctionRescue> {

	/**
	 * 自定义分页
	 *
	 * @param page 分页信息
	 * @param rescueListDTO 查询条件
	 * @return 数据集
	 */
	List<RescueListVo> selectMaintainMalfunctionRescuePage(IPage page, @Param("rescueListDTO") RescueListDTO rescueListDTO);


	/**
	 * 获取指派人员列表
	 * @param elevatorIds 电梯id
	 * @param type 1:电梯责任人2:负责组，3：上次维保人员
	 * @param planId
	 * @param userName
	 * @return 数据集
	 */
	@InterceptorIgnore(tenantLine = "on")
    List<UserInfoVo> getUserList(@Param("elevatorIds") List<Long> elevatorIds, @Param("type") Integer type, @Param("planId") Long planId, @Param("userName") String userName);
	/**
	 * 统计没有关联 user 的 id 数量（调度中）
	 * @return 调度中数量
	 */
	Integer selectCountNoHasUser();

	/**
	 * 统计已出发（有签到记录）工单数量
	 * @return 已出发工单数量
	 */
	Integer selectPlanHasSignCounts();

	/**
	 * 统计已完成的救援工单（状态4）数量
	 * @return 已完成工单数量
	 */
	Integer selectPlanFinishCounts();

	/**
	 * 统计已撤销（状态5）的工单数量
	 * @return 已撤销
	 */
	Integer selectPlanCancelCounts();

	/**
	 * 查询已完成订单的耗时（秒）
	 * @return 耗时（秒）
	 */
	Long selectWorkSeconds();

	/**
	 * 获取救援的电梯信息
	 * @param elevatorId 电梯id
	 * @return 数据集
	 */
	@InterceptorIgnore(tenantLine="on")
	RescueElevatorInfoVo getRescueElevatorInfo(@Param("elevatorId") Long elevatorId);


	/**
	 * 获取救援的项目信息
	 * @param buildingId
	 * @return 数据集
	 */
	RescueElevatorInfoVo getRescueBuildInfo(@Param("buildingId") Long buildingId);

	/**
	 * 获取救援工单的子维修工单
	 * @param planId 工单id
	 * @return 数据集
	 */
	List<PlanChildInfoVo> getPlanChildInfo(@Param("planId") Long planId);

	/**
	 * 获取发送消息用户
	 * @param userIds
	 * @return
	 */
    List<UserInfoVo> getMessageUserInfoVos(@Param("userIds") List<Long> userIds);

	/**
	 * 获取救援工单总分钟
	 * @return 分钟值
	 */
	Integer selectWorkMinutes();


	/**
	 * 地图-救援人员信息
	 * @return
	 */
	List<MapUserInfoVO> mapUserList(@Param("screenRoles") String screenRoles, @Param("keyword") String keyword);

	/**
	 * 地图人员基本信息
	 * @param userIds
	 * @param elevatorId
	 * @return
	 */
	List<MapUserInfoCardDetailVO> mapBaseUserInfos(@Param("userIds") List<Long> userIds, @Param("elevatorId") Long elevatorId);

	/**
	 * 今日任务
	 * @param userIds
	 * @return
	 */
	List<MaintainPlanContentVO> curDatePlan(@Param("userIds") List<Long> userIds);

	/**
	 * 地图-救援人员详情
	 * @param planId
	 * @return
	 */
	List<MapUserInfoDetailVO> mapUserDetails(@Param("planId") Long planId);

	/**
	 * 救援详情
	 * @param planId
	 * @return
	 */
	RescueOrderDetail rescueDetail(@Param("planId") Long planId);

	/**
	 * 救援详情列表
	 * @return
	 */
	@InterceptorIgnore(tenantLine="on")
	List<RescueOrderDetail> rescueDetailList();

	/**
	 * 梯联网救援详情
	 * @param tlwJoinId
	 * @return
	 */
	@InterceptorIgnore(tenantLine="on")
    TlwRescueDetailVO tlwRescueDetail(@Param("tlwJoinId") String tlwJoinId);

	/**
	 * 在保项目列表
	 * @return
	 */
    List<MaintainBuildingListVO> maintainBuildingList();

	/**
	 * 救援中项目统计
	 * @return
	 */
	List<RescueProjectScreenVO> rescueProjectScreen();

	MapUserInfoVO mapUserDetail(Long userId);

	List<SugarRescueListVO> selectSugarRescueList(@Param("searchDTO") SugarRescueSearchDTO searchDTO);

	/**
	 * 根据来源统计VO
	 * @param beginTime 开始时间
	 * @param endTime 结束时间
	 * @return 工单id 与字典key
	 */
    List<RescueCountByResourceVO> countByResource(Date beginTime, Date endTime);

	List<SugarRescueListVO> selectSugarRescueListAll();

    List<Map<String, Object>> selectArriveDurationOvertimeList(@Param("searchDTO") SugarRescueSearchDTO searchDTO);

    List<RescueBuildingElevatorListVO> selectBuildingElevatorList(@Param("buildingId") Long buildingId,@Param("keyword") String keyword);

	List<RescueBuildingElevatorPlanListVO> selectRescueElevatorEmptyList(@Param("buildingId") Long buildingId);

	/**
	 * 救援详情列表
	 * @param buildingId
	 * @param elevatorId
	 * @return
	 */
    MapRescuePlanDetailVO planRescueDetailListByBuildingId(@Param("buildingId") Long buildingId, @Param("elevatorId") Long elevatorId);

	/**
	 * 查询指定项目保养工单计划执行人
	 * @param buildingIds
	 * @return
	 */
	List<Long> selectBuildingRecentlyMaintainUser(@Param("buildingIds") List<Long> buildingIds);

	/**
	 * 工单救援详情
	 * @param planId
	 * @return
	 */
	PlanRescueDetailVO getRescueDetail(@Param("planId") Long planId);

	Map<String, Object> getMaintainBuildingElevatorCount();

	List<MaintainPlanContentExt> getRescueTodayFinishPlan();

    List<Long> selectRescueSugarUser(String tenantId);

	/**
	 * 在保项目列表
	 * @return
	 */
	List<EffectiveBuildingVO> effectiveBuildingList(@Param("buildingName") String buildingName, @Param("address") String address,
													@Param("phone") String phone, @Param("isOnlyShowRescue") boolean isOnlyShowRescue);

	/**
	 *
	 * @param buildingId
	 * @param elevatorNum
	 * @return
	 */
	List<EffectiveElevatorVO> effectiveElevatorList(@Param("buildingId") String buildingId, @Param("elevatorNum") String elevatorNum, @Param("isOnlyShowRescue") boolean isOnlyShowRescue);

    RescueRealTimeCountVO selectRealTimeCount();

	List<RescueRealTimePlanListVO> selectRealTimePlanList(@Param("planStatus") Integer planStatus,@Param("arrivalWarning") Integer arrivalWarning);

	List<RescueRealTimeListVO> selectRealTimeBuildingList();

	List<RescueRealTimeListVO> selectRealTimeUserList();

	List<MapUserInfoCardDetailPlanListVO> mapUserScreenDetailPlanList(@Param("userId") Long userId,@Param("typeStatus") Integer typeStatus);

	/**
	 * 获取当日所有未完成的工单
	 * @param userIds 用户id
	 * @return 数据集
	 */
	List<MaintainPlanContent> planListByUserIds(List<Long> userIds);

	/**
	 * 获取当日所有未签退的工单
	 * @param planIds 用户id
	 * @return 数据集
	 */
	List<MaintainPlanContent> getsignListByPlanIds(List<Long> planIds);


	/**
	 * 获取人员列表
	 * @param planAddUserSearchDTO 查询条件
	 * @return 数据集-
	 */
    List<UserInfoVo> getUserListV2(@Param("planAddUserSearchDTO") PlanAddUserSearchDTO planAddUserSearchDTO);


	/**
	 * 获取当天的用户的工单情况
	 * @param userId 用户id
	 * @return 数据集
	 */
	List<MaintainPlanContent> getTodayUserPlanInfo(Long userId);

	/**
	 * 获取当天用户任务列表
	 * @param userId
	 * @param typeStatus
	 * @return
	 */
    List<TodayTaskListVO> getTodayTaskList(@Param("typeStatus") Integer typeStatus, @Param("userId") Long userId);

	/**
	 * 调度分页
	 * @param dispatcherPageReqVO
	 * @param page
	 * @return
	 */
	IPage<DispatcherPageRespVO> dispatcherPage(@Param("reqParam") DispatcherPageReqVO dispatcherPageReqVO, IPage<DispatcherPageRespVO> page);

	/**
	 * 判断是否有关联的维修单
	 * @param id
	 * @return
	 */
	Boolean hasRelaMalOrder(Long id);

    List<Map<String, Object>> getBiRescuePlanDetailListV2();

	List<Map<String, Object>> getBiRescuePlanCountListV2();

}
